<?php 
function main() 
{
	$app = $_POST['app'];
	if ($app == 'online') {
		$date1 = "2012-12-21";
		$diff = abs(time() - strtotime($date1));
		$days = floor($diff / (60*60*24));
		$offset = floor(($days * 30) / 100);
		$drand = rand(0,$offset);
		$prand = rand(0,1);
		
		if ($prand) {
			return ($days - $drand);
		} else {
			return ($days + $drand);
		}
	}
	else if ($app == 'pviews') {
		$id = $_POST['id'];
		$views = get_post_meta($id, 'views', true);
		if ($views == '') {
			add_post_meta($id, 'views', 1, true);
		}
		else {
		 	$views = (int) $views;
			update_post_meta($id, 'views', $views + 1);
		}
		return 'OK';
	} else if ($app == 'related') {
		$id = $_POST['id'];
		the_related($id);
		return '';
	}
	
	return 'fail';
}
echo main();

?>